package com.smart.web;

import com.smart.service.CartService;
import com.smart.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by khan on 15-2-14.
 */
@Controller
public class OrderController {
    @Autowired
    private OrderService service;

    @Autowired
    private CartService cartServices;

    @RequestMapping(value="addorder",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String getUserByType(HttpServletRequest request,HttpServletResponse response,String goods_id,String userid) throws  Exception{
        long cartid = cartServices.getExistUnFinishCartid(Integer.valueOf(userid));
        if (cartid == 0){
            cartServices.createCart(Integer.valueOf(userid));
        }
        cartid = cartServices.getExistUnFinishCartid(Integer.valueOf(userid));
        return   String.valueOf( service.createOrder(Integer.valueOf(goods_id),cartid));
    }
}
